package cn.imokay;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

public class WatermarkTest {

    public static void main(String[] args) throws IOException, InvalidFormatException {
        String inputFilePath = "C:\\Users\\wmz\\Desktop\\开科水平项目经理.docx";
        String outputFilePath = "C:\\Users\\wmz\\Desktop\\开科水平项目经理-2.docx";
        String watermarkText = "理财有风险，投资需谨慎";
        String imagePath = "D:\\develop\\2024092622174316527.png";

        XWPFDocument document = new XWPFDocument(new FileInputStream(inputFilePath));
        XWPFParagraph paragraphT = document.createParagraph();
        //List<XWPFParagraph> paragraphs = document.getParagraphs();


        for (XWPFParagraph paragraph : document.getParagraphs())  {
            XWPFParagraph watermarkParagraph = WordWaterremark.createWatermarkParagraph(paragraphT,  watermarkText, imagePath);
            //paragraph.getCTP().addNew

            paragraph.getCTP().addNewPPr().set(watermarkParagraph.getCTP());
        }

        FileOutputStream out = new FileOutputStream(outputFilePath);
        document.write(out);
        out.close();
        document.close();
    }
} 